#if defined(__MMI_DSM_NEW__)&&defined(__MMI_SKYQQ__) && !defined(WIN32)

#include "MMI_Include.h"
#include "MessagesMiscell.h"
#include "med_utility.h"
#include "mdi_datatype.h"
#include "mdi_audio.h"

#ifdef __MMI_UCM__
#include "ucmgprot.h"
#endif

#include "mrp_include.h"


#include "sky_qq_open.h"
#if(MTK_VERSION<0x11B1132)
#include "MTPNP_PFAL_master_Def.h"
#endif
#include "MainMenuDef.h"

#ifdef __MMI_DUAL_SIM_MASTER__
#if(MTK_VERSION<=0x11B1132)
#include "mtpnp_ad_master_if.h"
#include "mtpnp_ad_master_common_def.h"
#endif
#endif

#include "Med_utility.h"
#include "mrporting.h"
#include "mmiDsmDef.h"
#include "mmidsmapi.h"
#include "mrp_application.h"
#include "mrp_unet.h"
#include "mrp_sms.h"
#include "mrp_include.h"
#include "PixComFontEngine.h"
#include "Wgui_categories_util.h"
#include "Wgui_include.h"
#include "Ucmsrvgprot.h"
#include "TimerEvents.h"//huangsunbo 20110425
#if(MTK_VERSION >= 0x11B1224)//huangsunbo 20120802 for 11B1224
#include "cbm_api.h"
#include "gpiosrvgprot.h"
#endif
#ifdef __MED_IN_ASM__
#define med_alloc_ext_mem(size) applib_asm_alloc_anonymous_nc(size)
#define med_alloc_ext_mem_cacheable(size) applib_asm_alloc_anonymous(size)
#define med_free_ext_mem(ptr) applib_asm_free_anonymous(*ptr)
#endif

#include "mmi_rp_app_mainmenu_def.h"//huangsunbo 20110425

extern stFontAttribute MMI_medium_font;
QQS32 QQ2008_write(MR_FILE_HANDLE f,void *p,QQU32 l);
MR_FILE_HANDLE QQ2008_open(const char* filename,  QQU32 mode);
QQS32 QQ2008_seek(MR_FILE_HANDLE f, QQS32 pos, int method);
QQS32 QQ2008_close(MR_FILE_HANDLE f);

#if (MTK_VERSION >= 0x0824)
#define INPUT_TYPE_PHONE_NUMBER						IMM_INPUT_TYPE_NUMERIC
#define INPUT_TYPE_ALPHANUMERIC_PASSWORD			IMM_INPUT_TYPE_ALPHANUMERIC_PASSWORD
#define INPUT_TYPE_ALPHANUMERIC_SENTENCECASE			IMM_INPUT_TYPE_SENTENCE

#ifndef WIN32
#define SOCK_STREAM		SOC_SOCK_STREAM	
#define SOCK_DGRAM		SOC_SOCK_DGRAM	
#define PF_INET 			SOC_PF_INET
#endif

#define always_ask_encode_data_account_id(id, a, b, c) 		cbm_encode_data_account_id(id, a-1, b, c)
#endif



extern void dsmGB2UCS2(char * src,char *dest);
extern U8 IS_SKYQQ_END_KEY;

extern void mmi_idle_display(void);



//数字键定义开关，如果有数字键就返回1，否则返回0。

QQS32 IsHaveNumKey(void)
{
	return 1;
}

//是否有中间键，五方向键的定义开关，如果是五方向键就返回1，否则返回0；
QQS32 IsHaveMidleKey(void)
{
	return 1;
}

//是否需要显示wifi这种联网方式的菜单；返回1就是显示菜单，否则就是不显示菜单。
QQS32 IsWIFIModle(void)
{
#ifdef __MMI_DSM_WIFI_SUPPORT__
	return 1;
#else
	return 0;
#endif
}
//好友上线后是否播放上线声音，加开这个接口的原因是因为有的机型出现播放上线声音死机问题
//返回1   代表好友上线时需要播放声音，返回0就是不播放
QQS32 GetOnlineSoundPlayFlag(void)
{
	return 1;
} 

//是否有振动的提示开关，返回1表示需要屏蔽振动菜单(当前的平台不支持振动)，
//否则就不需要屏蔽(即支持振动)；这里要反过来定义，是因为之前的版本没有这个开关，返回的默认是0；
QQS32 IsShieldVibrator(void)
{
	return 0;
}
/********************************************
函数名:QQS32 GetMallocMemSize(void)
描  述:返回需要申请内粗的大小
              如果使用静态内存模式那么返回值的大小必须和之前静态内存申请大小相同
参  数:无
返  回:返回需要申请内粗的大小
函数实现:huge2010-03-20
********************************************/
QQS32 GetMallocMemSize(void)
{
	//以下这个值可根据实际的需要进行配置，默认是90K，最好建议加开到120K，因为目前
	//好友的总数有的帐号出现有870个好友的，这样的超级用户内存不足；
#ifdef __MR_CFG_ENTRY_QQ_BEIZHU__
	return 170*1024;
#else
#ifdef __MMI_NGUAQ__
	return 150*1024;
#else
	return 130*1024;
#endif
#endif
}
 
U8 gIsUnreadMsg =0;
/***************************************
函数名:U8 GetUnreadMsgFlag(void)
描  述:返回当前QQ是否有未读消息
参  数:无
返  回:返回当前QQ是否有未读消息
函数实现:Ira 2010-11-4
****************************************/
U8 GetUnreadMsgFlag(void)
{
	return gIsUnreadMsg;
}

void SetUnreadMsgFlag(U8 state)
{
	gIsUnreadMsg = state;

	if(state == 1)
	{
		//有消息时点亮跑马灯;
	}
#ifdef __MR_CFG_ENTRY_QQ_BEIZHU__
	else if (state == 2)
	{
		//好友上线时	
	}
#endif
	else if(state ==0)
	{
		//消息读取完毕关闭跑马灯;
	}
}
/********************************************
函数名:QQS32 GetAutoConnectTimers(void)
描  述:返回重连次数的设置
参  数:无
返  回:返回重连次数的设置
函数实现:huge2010-03-20
********************************************/
QQS32 GetAutoConnectTimers(void)
{
	//以下这个值可根据实际的需要进行配置
	return 10;
}
void QQ2008FontSizeSet(void)
{
	gui_set_font(&MMI_medium_font);
}

S32 QQ2008_get_string_height(UI_string_type text)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	//UI_UNUSED_PARAMETER(text);
	//return 20;
	return gui_get_string_height(text);
   
}

S32 QQ2008_get_string_width(UI_string_type text)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 w, h;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    Get_StringWidthHeight((U8*) text, &w, &h);
    return (w);
}

//判断T卡是否存在。
static QQS8 TFalshDecide;

QQS8 GetPathFree(void)
{
	QQS8 ret;
	FS_DiskInfo		disk_info;
	S32				fs_ret;
	U16 path[4];
	char aPath[4] ={0};
       U8 drv;
	
	drv = MMI_CARD_DRV;
	sprintf(aPath,"%c:\\",drv);

	//AnsiiNToUnicodeString((S8 *)path,aPath,3);
	mmi_asc_n_to_ucs2((S8 *)path,aPath,3);
	
	fs_ret = FS_GetDiskInfo((PU16)path, &disk_info, FS_DI_BASIC_INFO|FS_DI_FREE_SPACE);

	if (fs_ret>=0)
	{
	/*
	以下#if 0中判断的意思是，如果空间小于500K就转成无T卡模式运行
	500K这个数值的原因是之前的所有版本如果T卡空间小于500K就强制提示退出。
	*/
	#if 0
		U64 disk_free_space;
		disk_free_space= disk_info.FreeClusters*disk_info.SectorsPerCluster*disk_info.BytesPerSector;
		if((disk_free_space/10) > 500*1024)
		{
			TFalshDecide = TRUE;
		}
		else 
		{
			TFalshDecide = FALSE;
		}
	#else
		TFalshDecide = TRUE;
	#endif
	}
	else
		TFalshDecide = FALSE;
	return TFalshDecide;
}

QQS8 GetPathFreeFlag(void)
{
	return TFalshDecide;
}

#define QQ2008_ROOT_PATH                                     "mythroad"

void QQ2008CreateRootDir(void)
{
	int ret;
	char temp[130] = {0};
	S8  fileBuf[65] ={0};
	extern void mr_fs_separator_vm_to_local(U8 * path);
#ifdef PURE_MEMORY
		sprintf(fileBuf,"%c:\\%s",MMI_CARD_DRV,QQ2008_ROOT_PATH);
#else
	if (GetPathFreeFlag())
		sprintf(fileBuf,"%c:\\%s",MMI_CARD_DRV,QQ2008_ROOT_PATH);
	else
		sprintf(fileBuf,"%c:\\%s",MMI_PUBLIC_DRV,QQ2008_ROOT_PATH);
#endif
	mr_fs_separator_vm_to_local((U8 *)fileBuf);
	dsmGB2UCS2((char*)fileBuf,(char*)temp);

	ret = FS_GetAttributes((WCHAR *)temp);
	
	if(ret < 0||(!(ret&FS_ATTR_DIR)))
	{	
		FS_CreateDir((WCHAR *)temp);
	}
}

//=====================shaowy===================//
void dsmHideStatusIcon(S16 icon_ID)
{
    HideStatusIcon(icon_ID);
}

#include "mmi_rp_app_imageviewer_def.h"
void dsmUpdateStatusIcons(void)
{
	#if(MTK_VERSION <0x11B1224)//huangsunbo 20120802 for 11B1224
	if(GetActiveScreenId()!= SCR_ID_IMGVIEW_VIEW && GetActiveScreenId()!= SCR_ID_IMGVIEW_FROM_FMGR)
	#else
	 if(GetActiveScreenId()!= SCR_ID_IMGVIEW_VIEW)
	#endif
		UpdateStatusIcons();
}

void dsmChangeStatusIconImage(S16 icon_ID, U16 image_ID)
{
	ChangeStatusIconImage(icon_ID, image_ID);
}

   
    
QQS8 IsOtherAPPShowing(void)
{ 
 #ifdef __DSM_MMI_APP_SRC__   
	 #ifdef _MMI_DSM_BIND_QQ_ 
		return dsm_mmi_get_showicon_status();
	 #else 
	  	return 0;
	 #endif 
#else  
 	return 0;   
 #endif   
}

void OtherAPPIconShow(int state)
{
 #ifdef __DSM_MMI_APP_SRC__
	 #ifdef _MMI_DSM_BIND_QQ_
		dsm_mmi_show_status_icon(state);
	 #endif
 #endif
}

void QQ2008MINIShowIdle(QQS8 flag)
{
 	//如果appid的图标在显示
	if (IsOtherAPPShowing())
		OtherAPPIconShow(QQ2008_BLINK_ICON);
	else
		QQFlicker(flag);
}


QQU8 QQmin=0;
void MINQQ(void)
{
	int lockflag = 0;
	if(GetSkyQQRunState() == QQ2008_RUN)
	{
		extern void QQ_CloseEditor(void);
		SetSkyQQRunState(QQ2008_BACK_RUN);
		//mr_app_set_state(QQ2008_BACK_RUN);
		//下面这个函数必须添加，否则会造成内存的泄露，因为平台已经退出
		QQ_CloseEditor();
		QQ2008MINIShowIdle(0);
		QQmin = 1;
	}
    	else if(GetSkyQQRunState() == QQ2008_PAUSE)
	{
		extern void QQ_CloseEditor(void);
		SetSkyQQRunState(QQ2008_BACK_RUN);
		//mr_app_set_state(QQ2008_BACK_RUN);
		//下面这个函数必须添加，否则会造成内存的泄露，因为平台已经退出
		QQ_CloseEditor();
		QQ2008MINIShowIdle(0);
		QQmin = 1;
	}
}

enum 
{
	QQ2008_ONLINE_STATUS,
	QQ2008_AWAY_STATUS,
	QQ2008_OFFLINE_STATUS,
	QQ2008_HIDE_STATUS	
};

//本函数用来唤醒QQ
void ActiveQQ2008Screen(void)
{
	extern void DsmSKY_QQ(void);
	if(SKY_QQ_IS_IDLE() == KAL_FALSE) 
		return;
		
	DsmSKY_QQ();
}


void SKYQQShowIdle(int status)
{
#if 1
	s16 status_icon_id;
	
	status_icon_id = STATUS_ICON_DSM_QQ_ONLINE;
	mr_trace("SKYQQShowIdle--status:%d--status_icon_id:%d",status,status_icon_id);
	if (IsOtherAPPShowing())
		OtherAPPIconShow(QQ2008_HIDE_ICON);
	if((GetQQ2008IconState() == QQ2008_OFFLINE_STATUS)&&(status == QQ2008_BLINK_ICON))
		status = QQ2008_SHOW_ICON;
	switch(status)
	{
		case QQ2008_SHOW_ICON:
		{
			switch(GetQQ2008IconState())
                	{	
				case QQ2008_OFFLINE_STATUS:
                    			dsmChangeStatusIconImage(status_icon_id,IMG_DSM_STATUS_ICON_QQ_OFFLINE);
                    		break;
                            case QQ2008_ONLINE_STATUS:
                    			dsmChangeStatusIconImage(status_icon_id,IMG_DSM_STATUS_ICON_QQ_ONLINE);
                            break;
                            case QQ2008_AWAY_STATUS:
                    			dsmChangeStatusIconImage(status_icon_id,IMG_DSM_STATUS_ICON_QQ_AWAY);
                            break;
                            case QQ2008_HIDE_STATUS:
                    			dsmChangeStatusIconImage(status_icon_id,IMG_DSM_STATUS_ICON_QQ_HIDE);
                            break;
                            default:
                    			dsmChangeStatusIconImage(status_icon_id,IMG_DSM_STATUS_ICON_QQ_OFFLINE);
                            break;
            		}     
            		
			dsmHideStatusIcon(status_icon_id);
			ShowStatusIcon(status_icon_id);
#ifdef __MMI_TOUCH_SCREEN__
			wgui_status_icon_bar_register_pen_event_handler(status_icon_id, WGUI_STATUS_ICON_BAR_PEN_SELECT_ICON,ActiveQQ2008Screen);
#endif	
			break;
		}
		case QQ2008_BLINK_ICON:
		{
			switch(GetQQ2008IconState())
                	{	
				case QQ2008_OFFLINE_STATUS:
                    			dsmChangeStatusIconImage(status_icon_id,IMG_DSM_STATUS_ICON_QQ_OFFLINE);
                    		break;
                            case QQ2008_ONLINE_STATUS:
                    			dsmChangeStatusIconImage(status_icon_id,IMG_DSM_STATUS_ICON_QQ_ONLINE);
                            break;
                            case QQ2008_AWAY_STATUS:
                    			dsmChangeStatusIconImage(status_icon_id,IMG_DSM_STATUS_ICON_QQ_AWAY);
                            break;
                            case QQ2008_HIDE_STATUS:
                    			dsmChangeStatusIconImage(status_icon_id,IMG_DSM_STATUS_ICON_QQ_HIDE);
                            break;
                            default:
                    			dsmChangeStatusIconImage(status_icon_id,IMG_DSM_STATUS_ICON_QQ_OFFLINE);
                            break;
            		}     
            
			dsmHideStatusIcon(status_icon_id);
			BlinkStatusIcon(status_icon_id);
#ifdef __MMI_TOUCH_SCREEN__
			wgui_status_icon_bar_register_pen_event_handler(status_icon_id, WGUI_STATUS_ICON_BAR_PEN_SELECT_ICON,ActiveQQ2008Screen);
#endif	
			break;
		}
		case QQ2008_HIDE_ICON:
		{
            		dsmHideStatusIcon(status_icon_id);
			//程序退出了要显示AppId桌面化的icon
			if (GetSkyQQRunState()==QQ2008_STOP)
			{
				if (IsOtherAPPShowing())
					OtherAPPIconShow(QQ2008_BLINK_ICON);
			}
			break;
		}
		default:
		{
			break;
		}

	}
	dsmUpdateStatusIcons();
#endif
}


QQS32 QQ2008DrivingActiveIsInCallDecide(void)
{
	  if (srv_ucm_query_call_count(SRV_UCM_ACTIVE_STATE, SRV_UCM_VOICE_CALL_TYPE_ALL, NULL) > 0)
		return  MMI_TRUE;
	else
		return MMI_FALSE;

	//return isInCall();
}

void* QQ2008Mem_malloc(QQS32 size)
{
#ifdef MEM_STATIC_MALLOC_DATA
	return;
#else
	void* ptr = NULL;
	ptr = (void* )med_alloc_ext_mem(size); 
	return ptr;
#endif
}
void  QQ2008Mem_free(void * ptr)
{
#ifdef MEM_STATIC_MALLOC_DATA
	return;
#else
	if (ptr)
	{
		med_free_ext_mem((void**)&ptr);
		ptr = NULL;
	}
	
#endif
}

#ifdef MEM_STATIC_MALLOC_DATA
//此处需要做同步的修改
char QQ2008Memory[QQ2008_MEM_LEN]={0};
#endif

void * QQ2008MemoryMalloc(void)
{
	void * ptr=NULL;
#ifdef MEM_STATIC_MALLOC_DATA
	ptr = QQ2008Memory;
#else
	ptr = QQ2008Mem_malloc((QQS32 )GetMallocMemSize());
#endif

 	return ptr;
}


/****************************************************************************
函数名:QQS32 QQ2008_imageDraw(QQU8* p, QQS16 x, QQS16 y)
描  述:绘图函数
参  数:
返  回:
****************************************************************************/
static unsigned short* getFullFileName(unsigned short * outputbuf, const char *filename);



#include "GameFramework.h"
#include "GameResDef.h"
#if(MTK_VERSION >= 0x10A1108)
//#include "mmi_rp_app_games_def.h"//huangsunbo todo 20110922
#endif
//extern int QQNeedPlayShank();

int  QQNeedPlayShake(void)
{
#ifdef __MMI_GAME__
	if(((GetActiveScreenId()==SCR_ID_GAME)||IsScreenPresent(SCR_ID_GAME))&&mmi_gfx_is_aud_on())
        	return 1;
#endif

#if defined(SXMOBI_MP4_SUPPORT) || defined(__SXMOBI_MTK_APPLICATION_MEDIAPLAYER__ENABLE__) 
         if(SXMOBI_Mp4IsActive()||AppleIsRun()||apple_mmi_in_platform())
                   return 1;
#endif
	//kal_prompt_trace(MOD_MMI,"DsmState()=%d,RunState=%d",GetDsmState(),GetSkyQQRunState());

	if((GetDsmState()!=0) && (GetSkyQQRunState()==QQ2008_BACK_RUN))
        	return 1;


#ifdef __MMI_VIDEO_RECORDER__//todo huangsunbo
#if(MTK_VERSION <0x11B1224)//huangsunbo 20120802 for 11B1224
	if(mmi_vdorec_is_in_app()||mdi_video_is_recording())//1224 todo
#else
	if(mdi_video_is_recording())
#endif
	         return 1;
#endif

#ifdef __MMI_VIDEO_PLAYER__//todo huangsunbo 20110713 后挂Q，在视频屏保界面，来QQ消息会没有声音
	if(mmi_vdoply_is_in_app()||mdi_video_is_playing())
	         return 1;
#endif


#ifdef __MMI_FM_RADIO__
	if(mmi_fmrdo_is_power_on())
	         return 1;
#endif 

#ifdef __MMI_TTS_FEATURES__
	if(g_tts_mmi_state == TTS_STATUS_PLAY)
		return 1;
#endif

#ifdef __MMI_AUDIO_PLAYER__
	if(mmi_audply_is_play_activated())
	         return 1;
#endif 

#ifdef __MMI_SLIDESHOW__
	if(mmi_slidshow_aud_is_playing())
	         return 1;
#endif

if(AlmIsTonePlaying())
         return 1;

if(QQ2008DrivingActiveIsInCallDecide())
         return 1;

if( !srv_prof_if_can_ring())//huangsunbo 20110803
		return 1;
    	return 0;
}



QQS32 QQ2008PlaySoundEx(U8 *audio_data,QQU32 len,QQS32 loop)
{
//huangsunbo 20110711 
#if  defined(TYM_TIME_SILENT_SUPPORT)
   if(current_ring_type_is_mute())
		return 1;
#endif
	


	if (QQNeedPlayShake())
		return 1;
    	if (audio_data != NULL)
    	{
		return  mdi_audio_play_string_with_vol_path((void*)audio_data,(U32)len,17,2,
			                                                  NULL,NULL,5,6);
	}
	else
	{
		return FALSE;
	}

}
//////////////////////////////////////////////////////////////////////////////
//network
typedef void (*timerCbFunc)(void);

QQS8 s_qqSimSel = -1;
/*static*/ QQS32 s_qq2008_unet_handle = UNET_INVALID_HANDLE;

extern T_DSM_DUALSIM_SET dsmDualSim;
extern int32 gDsmUseNVdataAccount;
extern void dsmGB2UCS2(char * src,char *dest);


#ifdef __MMI_DSM_WIFI_SUPPORT__
extern  BOOL isDsmVIAWIFI;
extern  int32 dsmWIFIId;
#endif

QQS32 QQ2008_initNetwork(MR_INIT_NETWORK_CB cb, const char *mode)
{	
#ifdef __MMI_DSM_WIFI_SUPPORT__
	if(isDsmVIAWIFI)
	{
		//abm_bearer2nw_id(ABM_E_SOCKET_BEARER_WIFI, 0, &dsmWIFIId);
		cbm_get_valid_account_id(CBM_WIFI, &dsmWIFIId);
		//dsmWIFIId = 134233656;/*不同的厂家可能值不同*///134233656
		s_qq2008_unet_handle = UNET_SPEC_WIFI_HANDLE;
		return unet_ApnAL_ActiveCntx((char *)dsmWIFIId, NULL, cb, UNET_SIM_MASTER - s_qqSimSel - 1/*(s_qqSimSel == -2) ? UNET_SIM_SLAVE : UNET_SIM_MASTER*/, &s_qq2008_unet_handle); 
	}
#endif

	if(gDsmUseNVdataAccount){
		return unet_ApnAl_ActiveCntx_Cust(cb, UNET_SIM_MASTER - s_qqSimSel - 1/*(s_qqSimSel == -2) ? UNET_SIM_SLAVE : UNET_SIM_MASTER*/, &s_qq2008_unet_handle);//coffee 20110411 for 4 sim card
	}else{
		return unet_ApnAL_ActiveCntx((char*)mode, NULL, cb, UNET_SIM_MASTER - s_qqSimSel - 1/*(s_qqSimSel == -2) ? UNET_SIM_SLAVE : UNET_SIM_MASTER*/, &s_qq2008_unet_handle);//coffee 20110411 for 4 sim car
	}
}

/****************************************************************************
函数名:QQS32 mr_getHostByName(const char *name, MR_GET_HOST_CB cb)
描     述:请求进行域名解析
参     数:name:
返     回:无
****************************************************************************/
QQS32 QQ2008_getHostByName(const char *name, MR_GET_HOST_CB cb)
{
	return unet_Soc_GetHostByName(name, cb, s_qq2008_unet_handle);
}

/****************************************************************************
函数名:QQS32 mr_socket(QQS32 type, QQS32 protocol)
描     述:创建一个socket
参     数:
返     回:创建成功的socket的句柄
****************************************************************************/
QQS32 QQ2008_socket(QQS32 type, QQS32 protocol)
{
	return unet_Soc_Create(type, protocol, s_qq2008_unet_handle);
 }

QQS32 QQ2008_connect(QQS32 s, QQS32 ip, QQU16 port, QQS32 type)
{
	return unet_Soc_Connect(s, ip, port, type);
}

QQS32 QQ2008_closeSocket(QQS32 s)
{
	return unet_Soc_Close(s);
}

QQS32 QQ2008_recv (QQS32 s, char *buf, int len)
{
	return unet_Soc_Recv(s, buf, len);
}

QQS32 QQ2008_send(QQS32 s, const char *buf, int len)
{
	return unet_Soc_Send(s, buf, len);
}

QQS32 QQ2008_recvfrom(QQS32 s, char *buf, int len, QQS32 *ip, QQU16 *port)
{
	return unet_Soc_Recvfrom(s, buf, len, ip, port);
}

QQS32 QQ2008_sendto(QQS32 s, const char *buf, int len, QQS32 ip, QQU16 port)
{
	return unet_Soc_Sendto(s, buf, len, ip, port);
}

#if 1//__CLOSE_QQ2008_SOCKET__
QQS32 QQ2008_closeNetwork(void)
{
	//extern void QQ2008_closeSocketAll(void);
	QQS32 ret;
    	//QQ2008_closeSocketAll();//huangsunbo 20110628  SKYENGINE.MTK10A_V2.008_20110622_x198版本不需要调用该函数
 	ret =  unet_ApnAL_CloseCntx(&s_qq2008_unet_handle);
     	return ret;
}
#endif //__CLOSE_QQ2008_SOCKET__

QQS32 QQ2008_checkConnect(QQS32 soc)
{
	return unet_Soc_State(soc);
}

//timer
QQS32 SKYQQ_timerStart(QQU16 t, timerCbFunc cb)
{
#if (MTK_VERSION > 0x0712)
	StartNonAlignTimer(SKYQQ_TIMER_START, t, cb);
#else
	StartTimer(SKYQQ_TIMER_START, (U32) t, cb);
#endif
	return MR_SUCCESS;
}

QQS32 SKYQQ_timerStop(void)
{
      StopTimer(SKYQQ_TIMER_START);
      return MR_SUCCESS;
}

/****************************************************************************
函数名:static int wstrlen(char * txt)
描  述:计算大端模式unicode字串的长度(byte)
参  数:txt:要求长度的字传
返  回:字传的长度
****************************************************************************/
 int wstrlen(char * txt)
{
	int lenth=0;
	unsigned char * ss=(unsigned char*)txt;

	while(((*ss<<8)+*(ss+1))!=0)
	{
		lenth+=2;
		ss+=2;
	}
	return lenth;
}

//files op
static unsigned short* getFullFileName(unsigned short * outputbuf, const char *filename) 
{
	QQU8 drv;
	QQS32 len;
	char *dest;
	U16 temp[DSM_MAX_FILE_LEN] = {0};
	//extern int wstrlen(char * txt);
	extern void mr_fs_separator_vm_to_local(U8 * path);
#ifdef PURE_MEMORY
	drv = MMI_CARD_DRV;	
#else
	if (GetPathFreeFlag())
		drv = MMI_CARD_DRV;	
	else
		drv = MMI_PUBLIC_DRV;	
#endif
	kal_wsprintf((unsigned short *)outputbuf, "%c:\\%s\\", (char)drv,QQ2008_ROOT_PATH);

	if(filename[0] !='\0'){
		len = wstrlen((char * )outputbuf);	
		dest = (char *)outputbuf + len;
		strcpy((char *)temp, (char *)filename);
		mr_fs_separator_vm_to_local((U8 *)temp);	 
		dsmGB2UCS2((char *)temp, dest);
	}
	return (unsigned short *)outputbuf;

}

QQS32 QQ2008_getLen(const char* filename)
{
	int filehandle;
	UINT size;
	QQS32 ret = MR_FAILED;
	U16 fullpathname[DSM_MAX_FILE_LEN] = {0};
	filehandle = FS_Open((WCHAR *)getFullFileName(fullpathname, filename), FS_READ_ONLY);
	if(filehandle >= FS_NO_ERROR){
		if(FS_GetFileSize( filehandle, &size) == FS_NO_ERROR){
			ret = (QQS32)size;
		}
		FS_Close(filehandle);
	}

	return ret;
}

MR_FILE_HANDLE QQ2008_open(const char* filename,  QQU32 mode)
{
	QQU32 new_mode = 0;
	U16 fullpathname[DSM_MAX_FILE_LEN] = {0};
	QQS32 f;
	if (mode & MR_FILE_RDONLY ) 
		new_mode |= FS_READ_ONLY;
	if (mode & MR_FILE_WRONLY ) 
		new_mode |= FS_READ_WRITE;
	if (mode & MR_FILE_RDWR ) 
		new_mode |= FS_READ_WRITE;
	if (mode & MR_FILE_CREATE ) 
		new_mode |= FS_CREATE;
	if(mode & MR_FILE_COMMITTED)
		new_mode |= FS_COMMITTED;
	if(mode & MR_FILE_SHARD)
		new_mode  |= FS_OPEN_SHARED;
	
	f = FS_Open((WCHAR *)getFullFileName(fullpathname, filename), new_mode);
	if (f < 0){
		f = NULL;
	}
	
	return f;
}

QQS32 QQ2008_read(MR_FILE_HANDLE f,void *p,QQU32 l)
{
	UINT readnum = 0;
	if(FS_Read(f, p, l, &readnum) == FS_NO_ERROR){
		return readnum;
	}
	return MR_FAILED;
}

QQS32 QQ2008_write(MR_FILE_HANDLE f,void *p,QQU32 l)
{
	UINT writenum = 0;
	if(FS_Write( f, p, l, &writenum) == FS_NO_ERROR){
		return writenum;
	}
	return MR_FAILED;
}

QQS32 QQ2008_close(MR_FILE_HANDLE f)
{
	if (FS_Close(f) == FS_NO_ERROR){
		return MR_SUCCESS;
	}
	return MR_FAILED;
}

QQS32 QQ2008_info(const char* filename)
{
	U16 fullpathname[DSM_MAX_FILE_LEN] = {0};  
	QQS32 ret;
	ret = FS_GetAttributes((WCHAR *)getFullFileName(fullpathname, filename));
	if (ret >= 0){
		if (ret & FS_ATTR_DIR){
			return MR_IS_DIR;
		}else{
			return MR_IS_FILE;
		}
	}
	return MR_IS_INVALID;
}

QQS32 QQ2008_seek(MR_FILE_HANDLE f, QQS32 pos, int method)
{
	if(FS_Seek( f, (int) pos, method) >= 0){
		return MR_SUCCESS;
	}
	return MR_FAILED;
}

QQS32 QQ2008_remove(const char* filename)
{
	U16 fullpathname[DSM_MAX_FILE_LEN] = {0};
	if (FS_Delete(( WCHAR *) getFullFileName(fullpathname, filename)) == FS_NO_ERROR){
		return MR_SUCCESS;
	}
	return MR_FAILED;
}

QQS32 QQ2008_rename(const char* oldname, const char* newname)
{
	U16 fullpathname_1[DSM_MAX_FILE_LEN] = {0};
	U16 fullpathname_2[DSM_MAX_FILE_LEN] = {0};
	if(FS_Rename(( WCHAR *)getFullFileName(fullpathname_1, oldname), ( WCHAR *)getFullFileName(fullpathname_2, newname)) == FS_NO_ERROR){
		return MR_SUCCESS;
	}
	return MR_FAILED;
}

QQS32 QQ2008_mkDir(const char* name)
{
	U16 fullpathname[DSM_MAX_FILE_LEN] = {0};
	if (FS_CreateDir(( WCHAR *)getFullFileName(fullpathname, name)) == FS_NO_ERROR){
		return MR_SUCCESS;
	}
	return MR_FAILED;
}

QQS32 QQ2008_rmDir(const char* name)
{
	U16 fullpathname[DSM_MAX_FILE_LEN] = {0};
	if(FS_RemoveDir(( WCHAR *) getFullFileName(fullpathname, name)) == FS_NO_ERROR){
		return MR_SUCCESS;
	}
	return MR_FAILED;
}

MR_FILE_HANDLE QQ2008_findStart(const char* name, char* buffer, QQU32 len)
{
	S8 NameBuffer[4];
	FS_DOSDirEntry file_info;
	U16 dsmFindBuffer[DSM_MAX_FILE_LEN] ;
	WCHAR CurrDir[DSM_MAX_FILE_LEN];
	U16 fullpathname[DSM_MAX_FILE_LEN] = {0};
	QQS32 ret;

	memset(dsmFindBuffer,0,sizeof(dsmFindBuffer));
	memset(NameBuffer,0,sizeof(NameBuffer));
	memset(CurrDir,0,sizeof(CurrDir));
	
	FS_GetCurrentDir((WCHAR*)CurrDir, DSM_MAX_FILE_LEN);
	FS_SetCurrentDir((const WCHAR*)getFullFileName(fullpathname, name));
	dsmGB2UCS2((char*)"*", (char*)NameBuffer);
	ret = FS_FindFirst((const WCHAR*)NameBuffer, 0, 0 ,&file_info, (WCHAR*)dsmFindBuffer, len);
	if(ret >= 0)
	{
		mr_str_ucs2_to_gb((char *)dsmFindBuffer,buffer,FALSE);
	}
	else
	{
		ret = MR_FAILED;
	}
	FS_SetCurrentDir((const WCHAR*) CurrDir);
	return ret;
}

QQS32 QQ2008_findGetNext(MR_FILE_HANDLE search_handle, char* buffer, QQU32 len)
{
	FS_DOSDirEntry file_info;
	U16 dsmFindBuffer[DSM_MAX_FILE_LEN];
	memset(dsmFindBuffer,0,sizeof(dsmFindBuffer));
	if(FS_FindNext( search_handle, &file_info, (WCHAR*)dsmFindBuffer, len) == FS_NO_ERROR)
	{
		mr_str_ucs2_to_gb((char *)dsmFindBuffer, buffer, FALSE);
		return MR_SUCCESS;
	}
	return MR_FAILED;
}

QQS32 QQ2008_findStop(MR_SEARCH_HANDLE search_handle)
{
	if (FS_FindClose(search_handle) == FS_NO_ERROR){
		return MR_SUCCESS;
	}
	return MR_FAILED;
}

void QQ2008_saveCurSimSet(void)
{
	//if(GetSkyQQRunState() != QQ2008_STOP)//huangsunbo 20110913
		s_qqSimSel = (QQS8)dsmDualSim.simId[dsmDualSim.curActive];
}


void QQ2008_restoreCurSimSet(void)
{
	if(s_qqSimSel != 0){
		 dsmDualSim.simId[dsmDualSim.curActive] = (QQS32)s_qqSimSel;
	}
}



//////////////////////////////for mtk mod//////////////////////////////////

/*********************************************************************
函数名:QQ2008_StartUpModeSwitchCheck
功能说明:
                当进行双卡切换的时候，这个函数可以判断
                切换后的模式和原来的模式有没有影响，有
                影响的话根据影响层度做不同的处理
                这个函数需在切换成功后再调用 
**********************************************************************/
void QQ2008_StartUpModeSwitchCheck(void)
{
#if 0//def __MMI_DUAL_SIM_MASTER__

	E_MTPNP_AD_NVRAM_STATUS curMode;
	int i = 0;

	if(GetSkyQQRunState() == QQ2008_STOP)
		return;

	curMode = MTPNP_AD_Get_Startup_Mode();
	if(curMode == MTPNP_AD_NVRAM_CARD1)
	{
		if(s_qqSimSel == -2)
		{
			unet_Soc_Break(s_qq2008_unet_handle);
		}
		s_qqSimSel = -1;
	}
	else if(curMode == MTPNP_AD_NVRAM_CARD2)
	{
		if(s_qqSimSel == -1)
		{
			unet_Soc_Break(s_qq2008_unet_handle);
		}
		s_qqSimSel = -2;
	}
	else if (curMode == MTPNP_AD_NVRAM_FLIGHT)
	{
		sky_qq_force_exit();
	}
#endif

}


int QQ2008_GetSimSel(void)
{
	return s_qqSimSel;
}


/******************************************************
函数名:void	ForceExitVM(void)
描  述:这个函数用于挂Q时强制退出整个VM程序
参  数:无
返  回:
函数实现:huge2010-03-20
修改日期:huge2010-03-28
修改内容:增加end键的处理
******************************************************/
void	ForceExitVM(void)
{
	//ExitDsmScr();
	mr_app_force_exit_dsm_screen();
	/*以下是另外一种实现模式*/
	/*
		dsmForceExit();
		GoBackHistory();
	*/
	/*
	FAE可以根据实际情况进行新的实现，只要强制退出我们的VM并返回到idle界面就可以
	*/
	if(IS_SKYQQ_END_KEY==1)
	{
		mmi_idle_display();
	}
	IS_SKYQQ_END_KEY = 0;
}

/******************************************************
函数名:void	SKYQQ_ReturnBack(void)
描  述:这个函数用于整个SKYQQ退出时返回到那个函数入口
参  数:无
返  回:
函数实现:huge2010-03-20
修改日期:huge2010-03-28
修改内容:增加是否是end键的判断
******************************************************/
#if (MTK_VERSION == 0x10A1108)
#include "mmi_rp_app_mainmenu_def.h"
#endif
void SKYQQ_ReturnBack(void)
{
	QQ2008_restoreCurSimSet();
	/*以下的返回后的启动曲奇功能，FAE可根据实际的需要启动不同的入口*/
	/*IS_SKYQQ_END_KEY这个键值如果不作为判断标准，就代表按挂机键和退出一样。即退出QQ后都会启动QQ入口*/
	if((GetDsmState() == DSM_STOP) && (0 == IS_SKYQQ_END_KEY))
	{
		IS_SKYQQ_END_KEY = 0;
		//DsmSKY_QQ();
	}
	else
	{
		if(IsScreenPresent(MAIN_MENU_SCREENID))
		{
			mmi_idle_display();
		}
	}
	IS_SKYQQ_END_KEY = 0;
}
/******************************************************
函数名:void SKYQQ_LockLCD_Buffer(void)
描  述:这个函数用于整个SKYQQ退出时启动VM入口前进行锁屏操作，开放出来的原因
		是有的手机调用锁屏会导致死机，如果不需要加锁制空
参  数:无
返  回:
函数实现:huge2010-04-01
******************************************************/
void SKYQQ_LockLCD_Buffer(void)
{
#if 0
	gdi_layer_lock_frame_buffer();
#endif
}
/******************************************************
函数名:void SKYQQ_LockLCD_Buffer(void)
描  述:这个函数用于整个SKYQQ退出时启动VM入口后的解锁操作和上面的对应使用，开
		放出来的原因是有的手机调用锁屏会导致死机,如果不需要解锁制空
参  数:无
返  回:
函数实现:huge2010-04-01
******************************************************/
void SKYQQ_UNLockLCD_Buffer(void)
{
#if 0
	//extern S32 MAIN_LCD_device_width,MAIN_LCD_device_height;
	gdi_layer_unlock_frame_buffer();
	gdi_layer_blt_previous(0, 0, UI_device_width- 1, UI_device_height - 1);
#endif
}

/******************************************************
函数名:void SKYQQ_LockLCD_Buffer(void)
描  述:这个函数用于判定是否可以点亮LCD，如果不允许点亮，那么返回0就可以了。
参  数:无
返  回:
函数实现:huge2010-04-01
******************************************************/
QQS8 IsCanTurnOnTheLCDLight(void)
{
#if(MTK_VERSION <0x11B1224)//huangsunbo 20120802 for 11B1224
	if(!IsBacklightOn())//1224 todo
#else
	if(!srv_backlight_is_on(SRV_BACKLIGHT_TYPE_MAINLCD))
#endif
		return 1;
	else
		return 0;
}

void GetQQStatusIconPos( QQS32 * x, QQS32 * y, QQS32 * w, QQS32 * h)
{
	mr_pal_status_icon_get_position(STATUS_ICON_DSM_QQ_ONLINE, x,  y, w, h);
}

kal_bool SKY_QQ_IS_IDLE(void)
{
#ifdef WIN32
	if(mmi_idle_is_active())
	{
		return KAL_TRUE;
	}
	else
	{
		return KAL_FALSE;
	}
#else
#if (MTK_VERSION > 0x09B0952)
	if(mmi_idle_is_active())
	{
		return KAL_TRUE;
	}
	else
	{
		return KAL_FALSE;
	}
#else
	if( IDLE_SCREEN_ID == GetActiveScreenId())
	{
		return KAL_TRUE;
	}
	else
	{
		return KAL_FALSE;
	}
#endif
#endif
}

/*如果定义了venus ui，需要截取触摸笔的位置是否在
skyqq icon坐标和范围，是:激活qq，否:不处理*/
kal_bool ActiveSkyQQbyIconPos( enum SKY_QQ_TOUCH_STATE state, QQS32 x, QQS32 y)
{
	QQS32 icon_x,icon_y,icon_w,icon_h;

	if(SKY_QQ_IS_IDLE() == KAL_FALSE)
		return KAL_FALSE;

	switch(state)
	{
		case SKY_QQ_P_TOUCH_STATE_DOWN:
		{
			GetQQStatusIconPos(&icon_x, &icon_y, &icon_w, &icon_h);

			if(x >= icon_x && y >= icon_y
			&& x <= icon_x + icon_w &&y <= icon_y+icon_h)
			{
				//gui_start_timer(50, ActiveQQ2008Screen);
				//todo
				ActiveQQ2008Screen();
				return KAL_TRUE;
			}
			break;
		}
		case SKY_QQ_P_TOUCH_STATE_UP:
		{
			break;
		}
		default:
			break;
	}

	return KAL_FALSE;
	
}
#endif//__MMI_QQ2008__

